package com.project.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.*;
import com.project.mapper.ISupplierRecordMapper;
import com.project.mapper.ISupplyGoodsMapper;
import com.project.mapper.ISupplyOrderMapper;
import com.project.service.ISupplierOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SupplierOrderServiceImpl implements ISupplierOrderService {

    @Autowired
    private ISupplyOrderMapper mapper;

    @Autowired
    private ISupplyGoodsMapper goodsMapper;

    @Autowired
    private ISupplierRecordMapper recordMapper;


    @Override
    public IPage<SupplyOrderEntity> findByItem(int pageNO, int status, int pageSize) {
        QueryWrapper<SupplyOrderEntity> qw = new QueryWrapper<>();
        qw.eq("s_status", status);
        return mapper.selectPage(new Page<>(pageNO, pageSize), qw);
    }

    @Override
    public List<SupplyGoodsEntity> findById(Integer customerId) {
        QueryWrapper<SupplyGoodsEntity> qw = new QueryWrapper<>();
        qw.eq("fk_supplyRef", customerId);
        return goodsMapper.selectList(qw);
    }

    @Override
    public void payment(Integer customerId, int status, String cause) {

        QueryWrapper<SupplyOrderEntity> qw = new QueryWrapper<>();
        qw.eq("s_supplyRef", customerId);
        SupplyOrderEntity supplier = mapper.selectOne(qw);
        supplier.setStatus(2);
        mapper.updateById(supplier);



    }
}
